package cc.bable.nexus.service;

import act.aaa.ActAAAService;
import cc.bable.nexus.entity.Admin;
import com.beust.jcommander.internal.Lists;
import org.osgl.aaa.Principal;
import org.osgl.util.C;

import java.util.List;
import java.util.Set;

/**
 * @author Andy
 */
public class AdminAAAService extends ActAAAService.Base<Admin> {

    public static final String PERM_ADMIN_READ = "admin-read";
    public static final String PERM_ADMIN_CHANGE = "admin-change";
    public static final String PERM_ROLE_READ = "role-read";
    public static final String PERM_ROLE_CHANGE = "role-change";
    public static final String PERM_USER_READ = "user-read";
    public static final String PERM_USER_CHANGE = "user-change";

    private static final String USER_KEY = "loginName";
    private static final int HASH_INTERATIONS = 1024;



    @Override
    protected String userKey() {
        return USER_KEY;
    }

    @Override
    public Principal findByName(String name) {
        Admin user = new Admin("admin");
        return this.principalOf(user);
    }

    @Override
    protected Set<String> permissionsOf(Admin admin) {
        List<String> list = Lists.newArrayList();
        list.add(PERM_ADMIN_READ);
        list.add(PERM_ADMIN_CHANGE);
        list.add(PERM_ROLE_READ);
        list.add(PERM_ROLE_CHANGE);
        list.add(PERM_USER_READ);
        list.add(PERM_USER_CHANGE);
        return C.set(list);
    }

    @Override
    protected boolean verifyPassword(Admin admin, char[] password) {
        return isMatchedPassword(admin, String.valueOf(password));
    }

    /**
     * 检查 password 匹配
     */
    private boolean isMatchedPassword(Admin admin, String password) {
        return true;
    }

}

